package Monster

import (
	"encoding/json"
	"bufio"
	"os"
	"io/ioutil"
)

type Monster struct {
	Name string
	Age int
	Skill string
}

func (m *Monster) Store() {
	data, err := json.Marshal(m)
	filePath := "a.txt"
	file, _ := os.Open(filePath, os.O_WRONLY | os.O_APPEND, 0666)
	defer file.Close()
	writer := bufio.NewWriter(file)
	writer.WriteString(data)
	return err
}

func (m *Monster) ReStore() {

	filePath := "a.txt"
	data, _ := ioutil.ReadFile(filePath)
	var m Monster
	err := json.Unmarshal(data, m)
	return err
}